#ifndef THINK_THINK_PROCESS_UTILS_H
#define THINK_THINK_PROCESS_UTILS_H

static char* think_process_utils =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | TopThink [ WE CAN DO IT JUST THINK IT ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2015 http://www.topthink.com All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: zhangyajun <448901948@qq.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\process;\n"
	"\n"
	"class Utils\n"
	"{\n"
	"\n"
	"    /**\n"
	"     * 转义字符串\n"
	"     * @param string $argument\n"
	"     * @return string\n"
	"     */\n"
	"    public static function escapeArgument($argument)\n"
	"    {\n"
	"\n"
	"        if (\'\' === $argument) {\n"
	"            return escapeshellarg($argument);\n"
	"        }\n"
	"        $escapedArgument = \'\';\n"
	"        $quote           = false;\n"
	"        foreach (preg_split(\'/(\")/i\', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {\n"
	"            if (\'\"\' === $part) {\n"
	"                $escapedArgument .= \'\\\\\"\';\n"
	"            } elseif (self::isSurroundedBy($part, \'%\')) {\n"
	"                // Avoid environment variable expansion\n"
	"                $escapedArgument .= \'^%\"\' . substr($part, 1, -1) . \'\"^%\';\n"
	"            } else {\n"
	"                // escape trailing backslash\n"
	"                if (\'\\\\\' === substr($part, -1)) {\n"
	"                    $part .= \'\\\\\';\n"
	"                }\n"
	"                $quote = true;\n"
	"                $escapedArgument .= $part;\n"
	"            }\n"
	"        }\n"
	"        if ($quote) {\n"
	"            $escapedArgument = \'\"\' . $escapedArgument . \'\"\';\n"
	"        }\n"
	"        return $escapedArgument;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 验证并进行规范化Process输入。\n"
	"     * @param string $caller\n"
	"     * @param mixed  $input\n"
	"     * @return string\n"
	"     * @throws \\InvalidArgumentException\n"
	"     */\n"
	"    public static function validateInput($caller, $input)\n"
	"    {\n"
	"        if (null !== $input) {\n"
	"            if (is_resource($input)) {\n"
	"                return $input;\n"
	"            }\n"
	"            if (is_scalar($input)) {\n"
	"                return (string) $input;\n"
	"            }\n"
	"            throw new \\InvalidArgumentException(sprintf(\'%s only accepts strings or stream resources.\', $caller));\n"
	"        }\n"
	"        return $input;\n"
	"    }\n"
	"\n"
	"    private static function isSurroundedBy($arg, $char)\n"
	"    {\n"
	"        return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];\n"
	"    }\n"
	"\n"
	"}\n"
	"\n"
;
#endif